package com.yh.web;

import com.yh.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author by 张晨光
 * @date 2024/1/18 14:19
 */
@Controller
public class RestfulController {
    @RequestMapping(value = "/user",method = RequestMethod.GET)
    @ResponseBody                                               //不再走视图解析器了
    public String findAllUsers(){
        System.out.println("查询所有的数据了....");
        return "findAll";
    }

    /**
     * @PathVariable:一般用在restful风格，url路径/{变量名}格式里面.
     * @param id
     * @return
     */
//    @RequestMapping(value = "/user/{id}",method = RequestMethod.GET)
    @GetMapping("/user/{id}")
    @ResponseBody
    public String findUserById(@PathVariable("id") Integer id){
        System.out.println("查找到"+id+"对应的user了");

        return "user";
    }

    /**
     * post增加
     * @param user
     */
//    @RequestMapping(value = "/user",method = RequestMethod.POST)
    @PostMapping("/user")
    @ResponseBody
    public void addUser(User user){
        System.out.println("增加用户了"+user);
    }

    /**
     * 修改
     * @param id
     */
//    @RequestMapping(value = "/user/{id}",method = RequestMethod.PUT)
    @PutMapping("/user/{id}")
    @ResponseBody
    public void updateUser(@PathVariable("id") Integer id){
        System.out.println("修改"+id+"对应的user信息");
    }

    /**
     * 删除：根据id来删除用户信息;Integer :null;
     * @param id
     */
    //@RequestMapping(value = "/user/{id}",method = RequestMethod.DELETE)
    @DeleteMapping("/user/{id}")
    @ResponseBody
    public void deleteUserById(@PathVariable("id")Integer id){
        System.out.println("删除"+id+"对应的user信息");
    }
}
